package com.pethome.web.controller;

import com.pethome.common.annotation.Log;
import com.pethome.common.core.controller.BaseController;
import com.pethome.common.core.domain.AjaxResult;
import com.pethome.common.core.page.TableDataInfo;
import com.pethome.common.enums.BusinessType;
import com.pethome.common.utils.poi.ExcelUtil;
import com.pethome.web.domain.Shelter;
import com.pethome.web.service.IShelterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收容管理Controller
 * 
 * @author ruoyi
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/web/shelter")
public class ShelterController extends BaseController
{
    @Autowired
    private IShelterService shelterService;

    /**
     * 查询收容管理列表
     */
    @PreAuthorize("@ss.hasPermi('web:shelter:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shelter shelter)
    {
        startPage();
        List<Shelter> list = shelterService.selectShelterList(shelter);
        return getDataTable(list);
    }

    /**
     * 导出收容管理列表
     */
    @PreAuthorize("@ss.hasPermi('web:shelter:export')")
    @Log(title = "收容管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shelter shelter)
    {
        List<Shelter> list = shelterService.selectShelterList(shelter);
        ExcelUtil<Shelter> util = new ExcelUtil<Shelter>(Shelter.class);
        util.exportExcel(response, list, "收容管理数据");
    }

    /**
     * 获取收容管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:shelter:query')")
    @GetMapping(value = "/{shelterId}")
    public AjaxResult getInfo(@PathVariable("shelterId") Long shelterId)
    {
        return success(shelterService.selectShelterByShelterId(shelterId));
    }

    /**
     * 新增收容管理
     */
    @PreAuthorize("@ss.hasPermi('web:shelter:add')")
    @Log(title = "收容管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shelter shelter)
    {
        return toAjax(shelterService.insertShelter(shelter));
    }

    /**
     * 修改收容管理
     */
    @PreAuthorize("@ss.hasPermi('web:shelter:edit')")
    @Log(title = "收容管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shelter shelter)
    {
        return toAjax(shelterService.updateShelter(shelter));
    }

    /**
     * 删除收容管理
     */
    @PreAuthorize("@ss.hasPermi('web:shelter:remove')")
    @Log(title = "收容管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shelterIds}")
    public AjaxResult remove(@PathVariable Long[] shelterIds)
    {
        return toAjax(shelterService.deleteShelterByShelterIds(shelterIds));
    }
}
